Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var e = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  r = require("../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../@babel/runtime/helpers/objectSpread2"),
  t = require("../../@babel/runtime/helpers/classCallCheck"),
  a = require("../../@babel/runtime/helpers/createClass"),
  o = require("../../config/index"),
  i = require("../../core/utils/index"),
  u = require("../../store/index"),
  s = function () {
    function s(e) {
      t(this, s),this.headers = {
        Authorization: wx.getStorageSync('token')
      }, this.SECRET_SIGN = "*js1(Uc_m12j%hsn#1o%cn1";
      var r = e.appId,
        a = e.business,
        o = e.reqsource,
        i = e.packagename;
      this.headers = n(n({}, this.headers), {})
    }
    return a(s, [{
      key: "upload",
      value: function (t) {
        var a = this,
          i = t.tempFilePaths,
          u = t.entryId,
          c = t.success,
          l = t.fail,
          f = t.onProgressUpdate;
        i.forEach(function () {
          var t = r(e().mark((function t(i) {
            var d, h, p;
            return e().wrap((function (t) {
              switch (t.prev = t.next) {
                case 0:
                  p = a.getHeader(h);
                  wx.uploadFile({
                    url: "".concat(o.REQUEST_JAVA_LIST.DEV, "/file/upload"),
                    filePath: i.url,
                    name: "file",
                    dataType: "json",
                    header: {
                      Authorization: wx.getStorageSync('token')
                    },
                    success: function (t) {
                      var res = JSON.parse(t.data)
                      20002 === res.code ? null == c || c({
                        url: i.url,
                        item: i,
                        fileId:res.data.id,
                        deliverUrl: res.data.url
                      }) : null == l || l({
                        item: i
                      })
                    },
                    fail: function (e) {
                      null == l || l({
                        err: e,
                        item: i
                      })
                    }
                  });
                case 2:
                case "end":
                  return t.stop()
              }
            }), t)
          })));
          return function (e) {
            return t.apply(this, arguments)
          }
        }())
      }
    }, {
      key: "sign",
      value: function (e, r, t) {
        var a = n({
            timestamp: e,
            nonce: r
          }, t),
          o = s.objKeySort(a),
          i = this.concatenateString(o);
        return s.sha256(i)
      }
    }, {
      key: "getHeader",
      value: function () {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
          r = Date.now(),
          t = s.random(1, 999999),
          a = this.sign(r, t, e),
          o = (0, i.getSystemInfoSync)(),
          c = (0, u.getState)(),
          l = c.storage;
        return n(n({}, this.headers))
      }
    }, {
      key: "concatenateString",
      value: function (e) {
        var r = "";
        return Object.keys(e).forEach((function (n) {
          return r += "".concat(n, "=").concat(e[n], "&")
        })), r + this.SECRET_SIGN
      }
    }], [{
      key: "objKeySort",
      value: function (e) {
        for (var r = Object.keys(e).sort(), n = {}, t = 0; t < r.length; t++) {
          var a = e[r[t]];
          "[object Object]" === Object.prototype.toString.call(a) && (a = JSON.stringify(s.objKeySort(a))), Array.isArray(a) && (a = JSON.stringify(a)), n[r[t]] = a
        }
        return n
      }
    }, {
      key: "random",
      value: function (e, r) {
        return Math.round(Math.random() * (r - e)) + e
      }
    }, {
      key: "sha256",
      value: function (e) {
        return function (e) {
          function r(e, r) {
            var n = (65535 & e) + (65535 & r);
            return (e >> 16) + (r >> 16) + (n >> 16) << 16 | 65535 & n
          }

          function n(e, r) {
            return e >>> r | e << 32 - r
          }

          function t(e, r) {
            return e >>> r
          }

          function a(e, r, n) {
            return e & r ^ ~e & n
          }

          function o(e, r, n) {
            return e & r ^ e & n ^ r & n
          }

          function i(e) {
            return n(e, 2) ^ n(e, 13) ^ n(e, 22)
          }

          function u(e) {
            return n(e, 6) ^ n(e, 11) ^ n(e, 25)
          }

          function s(e) {
            return n(e, 7) ^ n(e, 18) ^ t(e, 3)
          }
          return function (e) {
            for (var r = "0123456789abcdef", n = "", t = 0; t < 4 * e.length; t++) n += r.charAt(e[t >> 2] >> 8 * (3 - t % 4) + 4 & 15) + r.charAt(e[t >> 2] >> 8 * (3 - t % 4) & 15);
            return n
          }(function (e, c) {
            var l, f, d, h, p, N, m, v, g, y, b, S, O, U = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298],
              k = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225],
              C = new Array(64);
            for (e[c >> 5] |= 128 << 24 - c % 32, e[15 + (c + 64 >> 9 << 4)] = c, g = 0; g < e.length; g += 16) {
              for (l = k[0], f = k[1], d = k[2], h = k[3], p = k[4], N = k[5], m = k[6], v = k[7], y = 0; y < 64; y++) C[y] = y < 16 ? e[y + g] : r(r(r(n(O = C[y - 2], 17) ^ n(O, 19) ^ t(O, 10), C[y - 7]), s(C[y - 15])), C[y - 16]), b = r(r(r(r(v, u(p)), a(p, N, m)), U[y]), C[y]), S = r(i(l), o(l, f, d)), v = m, m = N, N = p, p = r(h, b), h = d, d = f, f = l, l = r(b, S);
              k[0] = r(l, k[0]), k[1] = r(f, k[1]), k[2] = r(d, k[2]), k[3] = r(h, k[3]), k[4] = r(p, k[4]), k[5] = r(N, k[5]), k[6] = r(m, k[6]), k[7] = r(v, k[7])
            }
            return k
          }(function (e) {
            for (var r = [], n = 0; n < 8 * e.length; n += 8) r[n >> 5] |= (255 & e.charCodeAt(n / 8)) << 24 - n % 32;
            return r
          }(e = function (e) {
            e = e.replace(/\r\n/g, "\n");
            for (var r = "", n = 0; n < e.length; n++) {
              var t = e.charCodeAt(n);
              t < 128 ? r += String.fromCharCode(t) : t > 127 && t < 2048 ? (r += String.fromCharCode(t >> 6 | 192), r += String.fromCharCode(63 & t | 128)) : (r += String.fromCharCode(t >> 12 | 224), r += String.fromCharCode(t >> 6 & 63 | 128), r += String.fromCharCode(63 & t | 128))
            }
            return r
          }(e)), 8 * e.length))
        }(e)
      }
    }, {
      key: "getFileSuffixName",
      value: function (e) {
        return /[.]/.exec(e) ? /[^.]+$/.exec(e)[0] : void 0
      }
    }]), s
  }();
exports.default = s;